import request from "@/utils/request";

//请求1:登陆
export function login(data) {
  return request({
    url: "/admin/acl/index/login",
    method: "post",
    data,
  });
}

//请求2:获取用户信息(根据token)
export function getInfo() {
  return request({
    url: "/admin/acl/index/info",
    method: "get",
  });
}

//请求3:退出登陆
export function logout() {
  return request({
    url: "/admin/acl/index/logout",
    method: "post",
  });
}

//请求4:获取管理用户分页列表 (swagger文档)
export const reqUserManageListByPage = (page, limit, username) => {
  return request.get(`/admin/acl/user/${page}/${limit}`, {
    params: { username },
  });
};

//请求5:新增/修改管理用户
export const reqAddOrEditUser = (addOrEditUserInfo) => {
  //若传入的数据有id 则是修改请求
  if (addOrEditUserInfo.id) {
    return request.put(`/admin/acl/user/update`, addOrEditUserInfo);
  } else {
    //添加请求
    return request.post(`/admin/acl/user/save`, addOrEditUserInfo);
  }
};

//请求6:根据id列表删除管理用户
export const reqDeleteAllSelection = (ids) =>{
  return request.post(`/admin/acl/user/batchRemove`,ids)
}

//请求7:删除管理用户
export const reqDeleteSingleUser = (id) =>{
  return request.delete(`/admin/acl/user/remove/${id}`)
}

//请求7:根据用户获取角色数据(角色信息)
export const reqUserRoleInfo = (userId) =>{
  return request.get(`/admin/acl/user/toAssign/${userId}`) 
}

//请求8：给角色分配权限
export const reqUserDoAssign = (data)=>{
  return request.post(`/admin/acl/user/doAssignRole`,data)
}